/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Entity.NhanVien;
import Entity.Quyen;
import Util.ComboBoxTagModel;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Dark_Knight
 */
public class formQuanLyNhanVien extends javax.swing.JPanel {

    private boolean isCreateNew = true;
    
    private BUS.NhanVienBUS nhanVienBUS;    
    private BUS.QuyenBUS quyenBUS;
    /**
     * Creates new form formQuanLyNhanVien
     */
    public formQuanLyNhanVien() {
        initComponents();
        quyenBUS = new BUS.QuyenImpl();
        nhanVienBUS = new BUS.NhanVienImpl();

        txtSDT.setTransferHandler(null);

        loadQuyen();
        loadNhanVien();
        disableAll();
    }
    
    protected void disableControl(javax.swing.JTextField obj) {
        obj.setText("");
        obj.setEnabled(false);
    }
    
    protected void disableControl(javax.swing.JButton obj) {        
        obj.setEnabled(false);
    }
    
    protected void disableAll() {
        disableControl(txtMa);
        disableControl(txtTen);
        disableControl(txtDiaChi);
        disableControl(txtSDT);
        disableControl(txtEmail);
        disableControl(txtDangNhap);
        disableControl(txtMatKhau);
        disableControl(btnXacNhan);
        disableControl(btnHuy);
    }
    
    protected void enableCreate() {
        enableEdit();
        txtDangNhap.setEnabled(true);
        txtMatKhau.setEnabled(true);
    }
    
    protected void enableEdit() {        
        txtTen.setEnabled(true);
        txtDiaChi.setEnabled(true);
        txtSDT.setEnabled(true);
        txtEmail.setEnabled(true);
        btnXacNhan.setEnabled(true);
        btnHuy.setEnabled(true);
    }
    
    protected void loadQuyen() {
        ComboBoxTagModel models = new ComboBoxTagModel();
        ArrayList list = quyenBUS.getAll();
        Quyen data;
        
        for (int i=0; i<list.size(); i++) {
            data = (Quyen) list.get(i);
            models.addElement(data.getTenQuyen(), data.getMaQuyen());
        }
        cmbChucVu.removeAllItems();
        cmbChucVu.setModel(models);
    }
    
    protected void loadNhanVien() {
        DefaultTableModel model = (DefaultTableModel) tbChiTiet.getModel();
        model.getDataVector().removeAllElements();
        
        nhanVienBUS.getAllDetail(model);
    }
    
    protected boolean getGender(String text) {
        if (text.equals("Nam")) {
            return true;
        } else {
            return false;
        }
    }
    
    protected void addNewNhanVien() {
        boolean gender = getGender(cmbGioiTinh.getSelectedItem().toString());  
        int MaQuyen = (Integer) ((ComboBoxTagModel)cmbChucVu.getModel()).getTagItem(cmbChucVu.getSelectedIndex());
        NhanVien data = new NhanVien(
                0,
                txtTen.getText(),
                gender,
                txtDangNhap.getText(),
                txtMatKhau.getText(),
                txtDiaChi.getText(),
                txtSDT.getText(),
                txtEmail.getText()
                );
        
        if (nhanVienBUS.add(data, MaQuyen)) {            
            disableAll();
            txtStatus.setText("Đã thêm Nhân Viên");
            loadNhanVien();
            setEnableTool(true);
        } else {
            JOptionPane.showMessageDialog(this, "Thêm Nhân Viên Không Thành Công");
            txtStatus.setText("Thêm Nhân Viên không thành công");
        }        
    }
    
    protected void loadEditInfor() {
        int index = tbChiTiet.getSelectedRow();
        DefaultTableModel model = (DefaultTableModel) tbChiTiet.getModel();
        
        txtMa.setText(model.getValueAt(index, 0).toString());
        txtTen.setText(model.getValueAt(index, 1).toString());
        cmbGioiTinh.setSelectedItem(model.getValueAt(index, 2));
        txtDiaChi.setText(model.getValueAt(index, 3).toString());
        txtSDT.setText(model.getValueAt(index, 4).toString());
        txtEmail.setText(model.getValueAt(index, 5).toString());
        cmbChucVu.setSelectedItem(model.getValueAt(index, 7));
    }
    
    protected void editNhanVien() {
        boolean gender = getGender(cmbGioiTinh.getSelectedItem().toString());  
        int MaQuyen = (Integer) ((ComboBoxTagModel)cmbChucVu.getModel()).getTagItem(cmbChucVu.getSelectedIndex());
        NhanVien data = new NhanVien(
                Integer.parseInt(txtMa.getText()),
                txtTen.getText(),
                gender,
                null,
                null,
                txtDiaChi.getText(),
                txtSDT.getText(),
                txtEmail.getText()
                );
        if (nhanVienBUS.edit(data, MaQuyen)) {
            txtStatus.setText("Đã cập nhật thông tin Nhân Viên");
            loadNhanVien();
            disableAll();
            setEnableTool(true);
        } else {
            JOptionPane.showMessageDialog(this, "Cập nhật thông tin Nhân Viên Không Thành Công");
            txtStatus.setText("Cập nhật thông tin Nhân Viên Không Thành Công");
        }
    }
    
    protected void deleteNhanVien() {
        int index = tbChiTiet.getSelectedRow();
        if (index == -1) return;
        
        DefaultTableModel model = (DefaultTableModel) tbChiTiet.getModel();
        int MaNV = (Integer) model.getValueAt(index, 0);
        
        if (nhanVienBUS.delete(MaNV)) {
            txtStatus.setText("Đã xóa Nhân Viên");
            loadNhanVien();            
        } else {
            JOptionPane.showMessageDialog(this, "Xóa Nhân Viên Không Thành Công");
            txtStatus.setText("Xóa Nhân Viên Không Thành Công");
        }
    }
    
    protected void setEnableTool(boolean isEnable) {
        btnThem.setEnabled(isEnable);        
        btnXoa.setEnabled(isEnable);
        btnSua.setEnabled(isEnable);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbChiTiet = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtMa = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtTen = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cmbGioiTinh = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        txtDiaChi = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtSDT = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtDangNhap = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtMatKhau = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cmbChucVu = new javax.swing.JComboBox();
        btnXacNhan = new javax.swing.JButton();
        btnHuy = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        btnThem = new javax.swing.JButton();
        btnSua = new javax.swing.JButton();
        btnXoa = new javax.swing.JButton();
        txtStatus = new javax.swing.JLabel();

        tbChiTiet.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Mã", "Họ Tên", "Giới Tính", "Địa Chỉ", "SDT", "Email", "Mã Quyền", "Tên Quyền"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbChiTiet);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông Tin", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel1.setText("Mã :");

        txtMa.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel2.setText("Tên :");

        txtTen.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel3.setText("Giới Tính :");

        cmbGioiTinh.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        cmbGioiTinh.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nam", "Nữ" }));

        jLabel4.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel4.setText("Địa Chỉ :");

        txtDiaChi.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel5.setText("SĐT :");

        txtSDT.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        txtSDT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtSDTKeyTyped(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel6.setText("Email :");

        txtEmail.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel7.setText("Tên Đăng Nhập :");

        txtDangNhap.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        jLabel8.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel8.setText("Mật Khẩu :");

        txtMatKhau.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        jLabel9.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel9.setText("Chức vụ :");

        cmbChucVu.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N

        btnXacNhan.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        btnXacNhan.setText("Xác nhận");
        btnXacNhan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXacNhanActionPerformed(evt);
            }
        });

        btnHuy.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        btnHuy.setText("Hủy Bỏ");
        btnHuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHuyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel4))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtMa, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtTen, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                    .addComponent(txtSDT, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                    .addComponent(cmbGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbChucVu, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDangNhap, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                            .addComponent(txtMatKhau, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                        .addComponent(btnXacNhan)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnHuy, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(txtDangNhap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtMatKhau, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 54, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnXacNhan)
                            .addComponent(btnHuy)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtMa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(txtSDT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(cmbGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(8, 8, 8)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbChucVu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))))
                .addContainerGap())
        );

        jToolBar1.setRollover(true);

        btnThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/Add.png"))); // NOI18N
        btnThem.setText("Thêm Nhân Viên");
        btnThem.setFocusable(false);
        btnThem.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnThem.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnThem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnThemMouseClicked(evt);
            }
        });
        jToolBar1.add(btnThem);

        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/edit.png"))); // NOI18N
        btnSua.setText("Sửa Thông Tin");
        btnSua.setFocusable(false);
        btnSua.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnSua.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSua.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnSuaMouseClicked(evt);
            }
        });
        jToolBar1.add(btnSua);

        btnXoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/delete.png"))); // NOI18N
        btnXoa.setText("Xóa Nhân Viên");
        btnXoa.setFocusable(false);
        btnXoa.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnXoa.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnXoa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnXoaMouseClicked(evt);
            }
        });
        jToolBar1.add(btnXoa);

        txtStatus.setFont(new java.awt.Font("Arial", 3, 12)); // NOI18N
        txtStatus.setForeground(new java.awt.Color(255, 0, 0));
        txtStatus.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        txtStatus.setText("status");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 877, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 857, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 821, Short.MAX_VALUE)
                        .addComponent(txtStatus)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtStatus)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnXacNhanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXacNhanActionPerformed
        if (isCreateNew) {
            addNewNhanVien();
        } else {
            editNhanVien();
        }        
    }//GEN-LAST:event_btnXacNhanActionPerformed

    private void btnThemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnThemMouseClicked
        enableCreate();
        isCreateNew = true;
        txtStatus.setText("Tạo Nhân Viên mới");
        
        setEnableTool(false);
    }//GEN-LAST:event_btnThemMouseClicked

    private void btnSuaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSuaMouseClicked
        if (tbChiTiet.getSelectedRow() == -1) {
            JOptionPane.showMessageDialog(this, "Hãy chọn Nhân Viên để thay đổi thông tin");
            return;
        }
         
        enableEdit();
        isCreateNew = false;
        txtStatus.setText("Sửa thông tin Nhân Viên");
        loadEditInfor();
        
        setEnableTool(false);
    }//GEN-LAST:event_btnSuaMouseClicked

    private void btnHuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHuyActionPerformed
        disableAll();
        setEnableTool(true);
    }//GEN-LAST:event_btnHuyActionPerformed

    private void btnXoaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnXoaMouseClicked
        deleteNhanVien();        
    }//GEN-LAST:event_btnXoaMouseClicked

    private void txtSDTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSDTKeyTyped
        Util.InstanceData.check(evt);
    }//GEN-LAST:event_txtSDTKeyTyped

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnHuy;
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btnThem;
    private javax.swing.JButton btnXacNhan;
    private javax.swing.JButton btnXoa;
    private javax.swing.JComboBox cmbChucVu;
    private javax.swing.JComboBox cmbGioiTinh;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JTable tbChiTiet;
    private javax.swing.JTextField txtDangNhap;
    private javax.swing.JTextField txtDiaChi;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtMa;
    private javax.swing.JTextField txtMatKhau;
    private javax.swing.JTextField txtSDT;
    private javax.swing.JLabel txtStatus;
    private javax.swing.JTextField txtTen;
    // End of variables declaration//GEN-END:variables
}
